package com.example.personalcenter;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.HashSet;
import java.util.Set;

public class InterestActivity extends AppCompatActivity {

    private final String[] INTERESTS = {"音乐", "电影", "阅读", "运动", "旅游", "美食", "摄影", "编程"};
    private final Set<String> selected = new HashSet<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interest);
        LinearLayout container = findViewById(R.id.container);
        Button btnConfirm = findViewById(R.id.btn_confirm);

        for (String s : INTERESTS) {
            CheckBox cb = new CheckBox(this);
            cb.setText(s);
            cb.setOnCheckedChangeListener((buttonView, isChecked) -> {
                if (isChecked) selected.add(s); else selected.remove(s);
            });
            container.addView(cb);
        }

        btnConfirm.setOnClickListener(v -> {
            if (selected.isEmpty()) {
                Toast.makeText(this, "至少选择一项兴趣", Toast.LENGTH_SHORT).show();
                return;
            }
            SharedPrefUtil.saveInterests(this, selected);
            startActivity(new Intent(this, HomeActivity.class));
            finish();
        });
    }
}